//
//  SceneCardView.m
//  SMTools
//
//  Created by fengsh on 2019/1/14.
//  Copyright © 2019年 fengsh. All rights reserved.
//

#import "SceneCardView.h"
#import <Masonry/Masonry.h>

@interface SceneCardView()
@property (nonatomic, strong) NSImageView            *img_icon;
@end

@implementation SceneCardView

- (instancetype)initWithFrame:(NSRect)frameRect
{
    self = [super initWithFrame:frameRect];
    if (self) {
        [self createControls];
        [self layoutControls];
    }
    return self;
}

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    
    // Drawing code here.
}

- (void)createControls
{
    self.img_icon = [[NSImageView alloc]init];
    self.img_icon.image = [NSImage imageNamed:@"card_bg"];
    self.lb_name = [[NSTextField alloc]init];
    [self.lb_name setEditable:NO];
    [self.lb_name setSelectable:NO];
    [self.lb_name setBezeled:NO];
    [self.lb_name setBordered:NO];
    [self.lb_name setAlignment:NSTextAlignmentCenter];
    [self.lb_name setStringValue:@""];
    [self.lb_name setFont:[NSFont fontWithName:@"STXingkai" size:24]];
    [self.lb_name setBackgroundColor:[NSColor clearColor]];
    [self.lb_name setTextColor:[NSColor redColor]];
    
//    NSLog(@"%@",[[[NSFontManager sharedFontManager] availableFontFamilies] description]);
    
    self.lb_department = [[NSTextField alloc]init];
    [self.lb_department setEditable:NO];
    [self.lb_department setSelectable:NO];
    [self.lb_department setBezeled:NO];
    [self.lb_department setBordered:NO];
    [self.lb_department setAlignment:NSTextAlignmentCenter];
    [self.lb_department setStringValue:@""];
//    [self.lb_department setFont:[NSFont fontWithName:@"STXingkai" size:14]];
    [self.lb_department setFont:[NSFont systemFontOfSize:13.0]];
    [self.lb_department setBackgroundColor:[NSColor clearColor]];
    [self.lb_department setTextColor:[NSColor redColor]];
    if (@available(macOS 10.11, *)) {
        [self.lb_department setMaximumNumberOfLines:2];
        [self.lb_department setLineBreakMode:NSLineBreakByWordWrapping];
    } else {
        // Fallback on earlier versions
        [self.lb_department.cell setLineBreakMode:NSLineBreakByWordWrapping];
    }
    
//    NSMutableParagraphStyle *textParagraph = [[NSMutableParagraphStyle alloc] init];
//    [textParagraph setLineSpacing:0.0];
//    NSDictionary *attrDic = [NSDictionary dictionaryWithObjectsAndKeys:textParagraph,NSParagraphStyleAttributeName, nil];
//    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"信息管理信息管理信息管理信息管理信息管理" attributes:attrDic];
//    [self.lb_department setAttributedStringValue:attrString];
//    [[self.lb_department cell] setTruncatesLastVisibleLine:YES];
    
    self.lb_phone = [[NSTextField alloc]init];
    [self.lb_phone setEditable:NO];
    [self.lb_phone setSelectable:NO];
    [self.lb_phone setBezeled:NO];
    [self.lb_phone setBordered:NO];
    [self.lb_phone setAlignment:NSTextAlignmentCenter];
    [self.lb_phone setStringValue:@"13800001399"];
    [self.lb_phone setFont:[NSFont fontWithName:@"STXingkai" size:14]];
    [self.lb_phone setBackgroundColor:[NSColor clearColor]];
    [self.lb_phone setTextColor:[NSColor redColor]];
    
    [self addSubview:self.img_icon];
    [self addSubview:self.lb_name];
    [self addSubview:self.lb_department];
//    [self addSubview:self.lb_phone];
}

- (void)layoutControls
{
    [self.img_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(0));
        make.bottom.equalTo(@(0));
        make.right.equalTo(@(0));
        make.left.equalTo(@(0));
    }];
    
    [self.lb_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(@(-30));
        make.leading.equalTo(@(30));
        make.height.equalTo(@(30));
        make.centerY.equalTo(@(0)).offset(-15);
    }];
    
    [self.lb_department mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(@(-30));
        make.leading.equalTo(@(30));
        make.height.greaterThanOrEqualTo(@(20));
        make.top.equalTo(self.lb_name.mas_bottom);
    }];
    
}

@end
